﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace visobj
{
    public class myDraw
    {
        PictureBox _LPictureBox;
        Bitmap _LBitmap;
        public myDraw(Bitmap m, PictureBox p)
        {
            _LPictureBox = p;
            _LBitmap = m;
        }
        public void drawbox(int x, int y, int size)
        {
            for (int i = 0; i < size; i++)
            {
                this.setPoint(x, y + i);
                this.setPoint(x + i, y);
                this.setPoint(x + size, y + i);
                this.setPoint(x + i, y + size);
            }
        }

        /// <remarks>Рисует точку по кординатам x, y</remarks>
        public void setPoint(int x, int y)
        {
            _LBitmap.SetPixel(x, y, Color.Black);
            _LBitmap.SetPixel(x + 1, y, Color.Black);
            _LBitmap.SetPixel(x, y + 1, Color.Black);
            _LBitmap.SetPixel(x + 1, y + 1, Color.Black);
            _LPictureBox.Image = _LBitmap;
            _LPictureBox.Refresh();
        }
        Bitmap _BReturn()  // Bitmap return
        {
            return _LBitmap;
        }
        unsafe public void Step_IntToInt(int* x, int* y)
        {
            int val1 = *x;
            int val2 = *y;
            if ((val1 - val2) > 0)
            {
                val1--;
                *x = val1;
            }
            if ((val1 - val2) < 0)
            {
                val1++;
                *x = val1;
            }
        }
        public void drawline(int x1, int y1, int x2, int y2, Color color)
        {
            for (; (x1 != x2) & (y1 != y2); )
            {
                _LBitmap.SetPixel(x1, y1, color);
                _LBitmap.SetPixel(x1 + 1, y1, color);
                _LBitmap.SetPixel(x1, y1 + 1, color);
                _LBitmap.SetPixel(x1 + 1, y1 + 1, color);
                unsafe
                {
                    Step_IntToInt(&x1, &x2);
                    Step_IntToInt(&y1, &y2);
                }
            }

        }
    }
}
